<?php
include_once '../header1.php';
?>
</head>
<body>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   else
   {
   if(!isset($_POST['Register']))
	{
$maxid=mysql_query("SELECT max(Training_Id) as maxId FROM training");

while($rowid=mysql_fetch_array($maxid))
{
$m_Id=$rowid['maxId'];
if($m_Id=="")
{
$Training_Id="T0001";
}
else
{
 $inum=substr("$m_Id",1);
$inn=($inum+1);
$Training_Id='T';
if(strlen($inn)<strlen($inum))
{
for($i=0;$i<(strlen($inum)-strlen($inn));$i++)
{
$Training_Id=$Training_Id.'0';
}
$Training_Id=$Training_Id.$inn;
}
else
{
$Training_Id=$Training_Id.$inn;
}
}
}
}
if(isset($_POST['Register']))
	   { 
	   $Training_Id=$_POST['Training_Id'];
	   
	   if($Training_Id!="")
	   {
$Com_Che=mysql_query("SELECT * FROM training WHERE Training_Id='$Training_Id'");
if($rowc=mysql_fetch_array($Com_Che))
		{
			$_SESSION['errorexi']="Sorry this Training's record already exists";
		}
		else
		{
		if($_SESSION['Access_Type']=="Administrator")
   {
	   require_once 'regtra.php';
}
	   else
	   {
	   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
	   }
}
}

}
	
?>
<?php
include_once "../header2.php";
?><?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
      <div id="lefttablereg">
  <form action="#" method="POST">
  <br/>
    <br/>
  <table width="453" height="108" border="0" class="tablefontv" >
    <tr>
      <td height="23" colspan="5"  scope="row" class="err"><?php
			if(isset($_POST['Register']))
{
	 if(isset($_SESSION['errornotallo']))
	{
		echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errornotallo'];
		unset($_SESSION['errornotallo']);
	}
	if(isset($_SESSION['errorin']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorin'];
		unset($_SESSION['errorin']);
	}
	if(isset($_SESSION['error']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errorexi']))
	{echo '<img src="../images/alert.jpg" width="12" height="12"/>';
		echo $_SESSION['errorexi'];
		unset($_SESSION['errorexi']);
	}
	
}
		?></td>
      
    </tr>
    <tr>
      <th width="17" rowspan="10"  scope="row">&nbsp;</th>
      <td width="28"  scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td width="187" height="25"  scope="row">
        
        
       Training Id:</td>
  
	   <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Training_Id' value='$Training_Id'/>";
echo '</td>';

}
else
{
echo '<td>';
if(isset($Training_Id))
{
echo "<input type='text' name='Training_Id' value='$Training_Id' readonly='readonly'/>";
}
else
{
echo "<input type='text' name='Training_Id'/>";
}

echo '</td>';

}?>
      <td width="203" rowspan="2">
      </td>
      </tr>
    
    <tr>
      <td scope="row"><font color="red" size="+2"><p align="center">*</p></font></td>
      <td height="25" scope="row">Training Name:</td>
       <?php
	   if(isset($_POST['Register']))
{
echo '<td>';
echo "<input type='text' name='Training_Name' value='$Training_Name'/>";
echo '</td>';

}
else
{
echo '<td >';
echo "<input type='text' name='Training_Name'/>";
echo '</td>';

}?>
      </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <th height="25" scope="row">&nbsp;</th>
      
	   
   <td width="203"></td>
      </tr>
     </table>
  <br/>
   <?php
  if(!isset($_POST['Register']))
	{
	}
    if(isset($_POST['Register']))
	{
	$Training_Id=$_POST['Training_Id'];
	$Training_Name=$_POST['Training_Name'];
	if($Training_Id==""||$Training_Name=="")
	{
	}
  }
   ?>
		<br/>
		<a href="regtrainini.php" class="reset">Reset |</a>
		<input name="Register" align="middle" type="submit" value="Register" class="buttonok"/>
 </form>
 </div>
  <div id="righttablereg">
  <?php
		if(isset($_POST['Register']))
{
if(isset($_SESSION['OK']))
{
$result=mysql_query("SELECT * FROM training");
echo '<br/>';
if(mysql_num_rows($result)!=0)
   {

echo '<table width="330" border="1" class="tablefontv">
<tr bgcolor="#6AB5FF">
<td><font color="#000000">Training Id</font></td>
<td><font color="#000000">Training Name</font></td>
<td><font color="#000000">Last Updated Date</font></td>
</tr>';

  while($row=mysql_fetch_array($result))
  {
  $Tra_Id=$_SESSION['Training_Id'];
   if($row['Training_Id']=="$Tra_Id")
  {
    echo '<tr bgcolor="#936">';
    echo '<td><font color="#000000">'.$row['Training_Id'].'</font></td>';
     echo '<td><font color="#000000">'.$row['Training_Name'].'</font></td>';
	 	echo '<td><font color="#000000">'.$row['Last_Updated_Date'].'</font></td>';
    echo '</tr>';
  unset($_SESSION['Training_Id']);
  }
 else
  {
    echo '<tr bgcolor="#CCCCCC">';
    echo '<td>'.$row['Training_Id'].'</td>';
    echo '<td>'.$row['Training_Name'].'</td>';
	echo '<td>'.$row['Last_Updated_Date'].'</td>';
    echo '</tr>';
  }
  }
   echo "</table>";

  }
  unset($_SESSION['OK']);
  }
  }
  
  ?>
  </div>
</div>
</div>
</div>
<div id="sidebar"><br/>
<div id="partners" class="boxed">
			<h2 class="title">TRAINING DETAILS</h2>
            </div>
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>

<?php

	}
?>
</body>
</html>